clear all
set more off
*capture log close
set logtype text
set matsize 10000

local mydate: di %tdDNCY date(c(current_date), "DMY")

*cd "X:"

global output 	"O:\returns"
global data		"D:" 
global work		"W:" 

*log using "${output}\inventors_patstat_`mydate'.log" , replace
/*  
\
()
{}
[]
=
`i'
 >
 <
 &
 |
*/

use "W:\data_prep\patent_data\patstat_19782013.dta"

* ADD: comparison of patents with and without known inventor


drop if shtun == ""
gen vuosi		= AppYear 
destring vuosi, replace
rename shtun shtun_lyh

bysort shtun vuosi: gen ind_id = _n

bysort shtun vuosi: gen pat_count_y = _N
bysort shtun: gen pat_count_all = _N

* patent statistics
* count of patents per inventor in a given year
tab pat_count_y
* count of patent per inventor overall
tab pat_count_all 
tab pat_count_all if ind_id == 1

bysort shtun vuosi: egen family_size_mean 	= mean(family_size)
bysort shtun vuosi: egen family_size_min	= min(family_size)
bysort shtun vuosi: egen family_size_max 	= max(family_size)

bysort shtun vuosi: egen claims_mean 		= mean(claims)
bysort shtun vuosi: egen claims_min 		= min(claims)
bysort shtun vuosi: egen claims_max 		= max(claims)

bysort shtun vuosi: egen bwd_cits_tot 		= total(bwd_cits)
bysort shtun vuosi: egen bwd_cits_mean 		= mean(bwd_cits)
bysort shtun vuosi: egen bwd_cits_min 		= min(bwd_cits)
bysort shtun vuosi: egen bwd_cits_max 		= max(bwd_cits)

bysort shtun vuosi: egen fwd_cits5_tot 		= total(fwd_cits5)
bysort shtun vuosi: egen fwd_cits5_mean 	= mean(fwd_cits5)
bysort shtun vuosi: egen fwd_cits5_min 		= min(fwd_cits5)
bysort shtun vuosi: egen fwd_cits5_max 		= max(fwd_cits5)

* patent level desc stat
tabstat family_size* claims* bwd_cits* fwd_cits5*, stat(mean sd p1 p25 p50 p75 p99 n)

drop if ind_id > 1
* inventor level patent desc stat
tabstat family_size* claims* bwd_cits* fwd_cits5* pat_count*, stat(mean sd p1 p25 p50 p75 p99 n)

keep shtun vuosi AppYear *_mean *_min *_max *_tot pat_count* syrtun_pat

*log close
save "W:\data_prep\patent_data\patstat_all.dta", replace
exit
